<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('销售发货订单列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>订单号：</label>
                                <input type="text" name="orderCode"/>
                            </li>
                            <li>
                                <label>供应商名称：</label>
                                <input type="text" name="supplierName"/>
                            </li>
                            <li>
                                <label>客户名称：</label>
                                <input type="text" name="customerName"/>
                            </li>
                            <li>
                                <label>业务责任人：</label>
                                <input type="text" name="businessManager"/>
                            </li>
                            <li>
                                <label>承运商名称：</label>
                                <input type="text" name="carriersName"/>
                            </li>
                            <li>
                                <label>结算方式：</label>
                                <select name="settlementWay" class="form-control" th:with="type=${@dict.getType('settlement_way')}">
                                    <option value="">请选择</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                            th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.addTab()" shiro:hasPermission="order:deliveryorder:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-success multiple" onclick="$.operate.audit()" shiro:hasPermission="order:deliveryorder:audit">
                    <i class="fa fa-bookmark"></i> 审核
                </a>
                <!--<a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="order:deliveryorder:edit">-->
                    <!--<i class="fa fa-edit"></i> 修改-->
                <!--</a>-->
                <!--<a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="order:deliveryorder:remove">-->
                    <!--<i class="fa fa-remove"></i> 删除-->
                <!--</a>-->
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="order:deliveryorder:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('order:deliveryorder:edit')}]];
        var removeFlag = [[${@permission.hasPermi('order:deliveryorder:remove')}]];
        var settlementDatas = [[${@dict.getType('settlement_way')}]];
        var orderStatusDatas = [[${@dict.getType('order_status')}]];
        var deliveryStatusDatas = [[${@dict.getType('delivery_status')}]];
        var unitDatas = [[${@dict.getType('product_unit')}]];
        var prefix = ctx + "order/deliveryorder";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                auditUrl: prefix + "/audit",
                modalName: "销售发货订单",
                detailView: true,
                onExpandRow : function(index, row, $detail) {
                    initChildTable(index, row, $detail);
                },
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '发货订单id',
                    visible: false
                },
                {
                    field: 'orderCode',
                    title: '订单号'
                },
                // {
                //     field: 'supplierId',
                //     title: '供应商ID'
                // },
                {
                    field: 'supplierName',
                    title: '供应商名称'
                },
                // {
                //     field: 'customerId',
                //     title: '客户ID'
                // },
                {
                    field: 'customerName',
                    title: '客户名称'
                },
                {
                    field: 'businessManager',
                    title: '业务责任人'
                },
                // {
                //     field: 'carriersId',
                //     title: '承运商ID'
                // },
                {
                    field: 'carriersName',
                    title: '承运商名称'
                },
                {
                    field: 'amounts',
                    title: '销售金额'
                },
                {
                    field: 'logisticsFee',
                    title: '物流费用'
                },
                {
                    field: 'settlementWay',
                    title: '结算方式',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(settlementDatas, value);
                    }
                },
                {
                    field: 'deliveryTime',
                    title: '发货时间'
                },
                {
                    field: 'orderStatus',
                    title: '订单状态',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(orderStatusDatas, value);
                    }
                },
                {
                    field: 'deliveryStatus',
                    title: '发货状态',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(deliveryStatusDatas, value);
                    }
                },
                {
                    field: 'remark',
                    title: '备注'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if(row.orderStatus == 0){
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        }else if(row.orderStatus == 1 && row.deliveryStatus == 0){
                            actions.push('<a class="btn btn-primary btn-xs " href="javascript:void(0)" onclick="deliveryStatus(\'' + row.id + '\')"><i class="fa fa-ticket"></i>确认发货</a> ');
                        }

                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });


        initChildTable = function(index, row, $detail) {
            var childTable = $detail.html('<table style="table-layout:fixed"></table>').find('table');
            $(childTable).bootstrapTable({
                url: prefix + "/item/list",
                method: 'post',
                sidePagination: "server",
                contentType: "application/x-www-form-urlencoded",
                queryParams: {
                    mainId: row.id
                },
                columns: [
                    {
                        field: 'id',
                        title: 'id',
                        visible: false
                    },
                    {
                        field: 'goodsCode',
                        title: '商品编码'
                    },
                    {
                        field: 'goodsName',
                        title: '商品名称'
                    },
                    {
                        field: 'goodsUnit',
                        title: '单位',
                        formatter: function(value, row, index) {
                            return $.table.selectDictLabel(unitDatas, value);
                        }
                    },
                    {
                        field: 'planNumber',
                        title: '数量'
                    },
                    {
                        field: 'price',
                        title: '单价'
                    },
                    {
                        field: 'amount',
                        title: '总价'
                    },
                    {
                        field: 'remark',
                        title: '要求'
                    }
                ]

            });

        };

        function deliveryStatus(id){
            $.modal.confirm("确认发货吗？", function () {
                $.operate.post(prefix + "/deliveryStatus", {"id": id, "deliveryStatus": '1'});

            })
        }
    </script>
</body>
</html>